//****************************************************************/
//Creation History
// Company: GZ office
// NAME:    CostCenterServlet.java
// TITLE:   Cost Center Column Accessibility Maintenance
// BY:      Oscar Bai
// DATE:    03/03/2003
//******************************************************************/
//Modification History
//******************************************************************/
// CR 1347  Miranda Lin  11-Aug-2004
// ADD: added division id
//******************************************************************/



package admin.system.costcenter;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.servlet.*;
import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.*;

public class CostCenterServlet
  extends DBServlet {

  @Override
protected String perform(  HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
  {
      String action = new String(request.getParameter("formAction"));
      CostCenterBean costCenter = CostCenterProcess.createBean();
      costCenter.setCost_Center_id(request.getParameter("cost_center_id"));
      costCenter.setCost_Center_name(request.getParameter("cost_center_name"));
      costCenter.setCost_Center_des(request.getParameter("cost_center_des"));
      costCenter.setUpd_user(getUser().getUser_id());
      costCenter.setUpd_date(DateFormatter.format(this.getDate()));
/* CR 1347 */
      costCenter.setDivision_id(request.getParameter("division_id"));
/* CR 1347 */
      if (action.trim().equalsIgnoreCase("Create"))
      {
         costCenter.setCrt_user(getUser().getUser_id());
         costCenter.setCrt_date(DateFormatter.format(this.getDate()));
        if (CostCenterProcess.insert(this.getConnection(),costCenter)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure");
      }
      else if (action.trim().equalsIgnoreCase("Update"))
        if (CostCenterProcess.update(this.getConnection(),costCenter)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure.");
      else if (action.trim().equalsIgnoreCase("Delete"))
        if (CostCenterProcess.delete(this.getConnection(),costCenter)>0)
            message.setMessage("Delete successfully.");
        else
            message.setMessage("Delete failure.");
      else
            message.setMessage("No action mapped!");
      return "system/CostCenterSearch.jsp";
  }
}


